
from numpy import true_divide
import pandas as pd
import pymongo


class PdStocks:

    #字段解析，代码，日期，开，高，低，收，前一日收，涨跌额，涨跌幅，成交量（手），成交额（千元），
    @classmethod
    def getDaily(cls, code):
        mongo = pymongo.MongoClient('mongodb://localhost:27017/',connect=False)
        data = mongo.ceshi.daily.find_one({'code':code})['data']

        if data:
            data = pd.DataFrame(data,columns=["code","date","open","high","low","close","preClose","change","pctChange","vol","amount"]).iloc[::-1]
            data = data.reset_index()
            del data['index']
            return data
        else:
            return False